<template>
<!--  <div>-->
<!--    <header>-->
<!--      <div class="collapse bg-dark" id="navbarHeader">-->
<!--        <div class="container">-->
<!--          <div class="row">-->
<!--            <div class="col-sm-8 col-md-7 py-4">-->
<!--              <h4 class="text-white">About1</h4>-->
<!--              <p class="text-muted">Add some information about the album below, the author, or any other background context. Make it a few sentences long so folks can pick up some informative tidbits. Then, link them off to some social networking sites or contact information.</p>-->
<!--            </div>-->
<!--            <div class="col-sm-4 offset-md-1 py-4">-->
<!--              <h4 class="text-white">Contact</h4>-->
<!--              <ul class="list-unstyled">-->
<!--                <li><a href="#" class="text-white">Follow on Twitter</a></li>-->
<!--                <li><a href="#" class="text-white">Like on Facebook</a></li>-->
<!--                <li><a href="#" class="text-white">Email me</a></li>-->
<!--              </ul>-->
<!--            </div>-->
<!--          </div>-->
<!--        </div>-->
<!--      </div>-->
<!--      <div class="navbar navbar-dark bg-dark shadow-sm">-->
<!--        <div class="container d-flex justify-content-between">-->
<!--          <a href="#" class="navbar-brand d-flex align-items-center">-->
<!--            <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" aria-hidden="true" class="mr-2" viewBox="0 0 24 24" focusable="false"><path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"></path><circle cx="12" cy="13" r="4"></circle></svg>-->
<!--            <strong>Album</strong>-->
<!--          </a>-->
<!--          <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarHeader" aria-controls="navbarHeader" aria-expanded="false" aria-label="Toggle navigation">-->
<!--            <span class="navbar-toggler-icon"></span>-->
<!--          </button>-->
<!--        </div>-->
<!--      </div>-->
<!--    </header>-->
<!--  </div>-->
  <header>
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
      <div class="container">
        <a class="navbar-brand" href="#">
          <i class="fa fa-video-camera"></i>&nbsp;Java课程
        </a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>

        <div class="collapse navbar-collapse" id="navbarSupportedContent">
          <ul class="navbar-nav mr-auto">
            <li class="nav-item active">
              <router-link class="nav-link" to="/">主页 <span class="sr-only">(current)</span></router-link>
            </li>
            <li class="nav-item active">
              <router-link class="nav-link" to="/list">全部课程</router-link>
            </li>
            <li class="nav-item dropdown active">
              <a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-expanded="false">
                更多
              </a>
              <div class="dropdown-menu">
                <a class="dropdown-item" href="#">关于我们</a>
                <a class="dropdown-item" href="#">渠道合作</a>
                <div class="dropdown-divider"></div>
                <a class="dropdown-item" href="#">更多信息</a>
              </div>
            </li>
          </ul>
          <span v-show="loginMember.id" class="text-white pr-3">您好：{{loginMember.name}}</span>
          <button v-show="loginMember.id" class="btn btn-outline-light my-2 my-sm-0" type="submit" v-on:click="logout()">退出</button>
          <button v-show="!loginMember.id" class="btn btn-outline-light my-2 my-sm-0" type="submit" v-on:click="openLoginModal()">登录/注册</button>
        </div>
      </div>
    </nav>

    <the-login ref="loginComponent"></the-login>
  </header>
</template>

<script>
import TheLogin from "./login";
export default {
  name: "the-header",
  components: {TheLogin},
  data: function () {
    return {
      loginMember: {},
    }
  },
  mounted: function () {
    let _this = this;
    _this.loginMember = Tool.getLoginMember();
  },
  methods: {
    /**
     * 打开登录注册窗口
     */
    openLoginModal() {
      let _this = this;
      _this.$refs.loginComponent.openLoginModal();
    },
    setLoginMember(loginMember) {
      let _this = this;
      _this.loginMember = loginMember;
    },
    /**
     * 退出登录
     */
    logout() {
      let _this = this;
      _this.$ajax.get(process.env.VUE_APP_SERVER + '/business/web/member/logout/' + _this.loginMember.token).then((response)=> {
        const resp = response.data;
        if (resp.success) {
          Toast.success("退出登录成功");
          Tool.setLoginMember(null);
          _this.loginMember = {};
          _this.$router.push("/");
        } else {
          Toast.warning(response.data.message);
        }
      })
    }
  },
}
</script>

<style scoped>

</style>